<?
class user{
	var $id_user;
	var $name;
	var $lname;
	var $photo;
	var $sex;
	var $tel;
	var $id_design;
		
	var $mnum;
	var $res;
	
	/*
	function user($id=null){
		if($id ==null)
		{}//$this->res = $this->cone->query("SELECT * FROM users;");
		else 
			$this->res = $this->cone->query("SELECT * FROM users WHERE id_user=$id;"); 
		//die("num is ".$this->mnum);
	}*/
	
	function get_info($user_id){
		$this->res = mysql_query("SELECT * FROM users where id_user = $user_id;");
		$this->mnum = mysql_num_rows($this->res);
	}
	
	function fillinfo(){
			if($obj = mysql_fetch_object($this->res)){
				$this->id_user = $obj->id_user;
				$this->name = $obj->name;
				$this->lname = $obj->lname;
				$this->photo = $obj->photo;
				$this->sex = $obj->sex;
				$this->tel = $obj->tel;
				$this->id_design = $obj->id_disign_fk;
			return true;
			}else return false;
	}
	function add($fname,$lname){
		//echo "INSERT INTO users VALUES ('', '$this->username','$this->password', '$this->firstname', '$this->phone', '$this->mail', '$this->stagecotier', '$this->gendre', '$this->hauturier', '$this->cotier', '$this->carte', '$this->active');";
		//die("add");
		$this->name  = $fname;
		$this->lname = $lname;
		mysql_query("INSERT INTO users(name,lname) VALUES ('$this->name', '$this->lname');");		
		return  mysql_insert_id();
	}
	
	function edit_photo($photo){
		mysql_query("update users set photo = '$photo' where id_user = $this->id_user);");
	}
	
	
	
	
	function edit(){
		//echo "UPDATE users SET  guard_password_tx='$this->password', guard_lastname_tx='$this->lastname', guard_firstname_tx='$this->firstname', guard_phone_tx='$this->phone', guard_mail_tx='$this->mail', guard_cotier_stage_n='$this->stagecotier', guard_gender_n='$this->gendre', guard_hauturier_n='$this->hauturier', guard_cotier_n='$this->cotier', guard_carte_verte_n='$this->carte' WHERE guard_id_n=$this->id;";
		return $this->cone->query("UPDATE users SET  guard_password_tx='$this->password', guard_lastname_tx='$this->lastname', guard_firstname_tx='$this->firstname', guard_phone_tx='$this->phone', guard_mail_tx='$this->mail', guard_cotier_stage_n='$this->stagecotier', guard_gender_n='$this->gendre', guard_hauturier_n='$this->hauturier', guard_cotier_n='$this->cotier', guard_carte_verte_n='$this->carte' WHERE guard_id_n=$this->id;");		
	}
	function drop(){
		echo "DELETE FROM users WHERE guard_id_n=$this->id;";
		return  $this->cone->query("DELETE FROM users WHERE guard_id_n=$this->id;");
		}
	function activateaccount($id){
		return $this->cone->query("UPDATE users SET guard_activated_n='1' where guard_id_n=$id");
	}
	function isactive($id){
		$res1 = $this->cone->query("SELECT guard_activated_n FROM users WHERE guard_id_n=$id;"); 		
		//$res1 = mysql_fetch_row($this->res);
		//echo "SELECT guard_activated_n FROM users WHERE guard_id_n=$id;";
		$obj = mysql_fetch_row($res1);
		if($obj[0]=='1') return true; else return false; 
	}
	function checkemail($mail){
	//$res1 = $this->cone->query("SELECT guard_id_n FROM users WHERE guard_mail_tx like '$mail';"); 	
	//echo "SELECT guard_id_n FROM users WHERE guard_mail_tx like '$mail';";
	//$num = mysql_num_rows($res1);
	
		$resu = $this->cone->query("SELECT guard_id_n FROM users WHERE guard_mail_tx like '$mail';");		
		$mnum = mysql_num_rows($resu);
		//echo "SELECT guard_id_n FROM users WHERE guard_mail_tx like '$mail';";
	//$n = $this->mnum;
	//die($mnum);
	if($mnum > 0){
		$obj1 = mysql_fetch_row($resu);
		$id = $obj1[0];
		return $id;
	 }else return "active"; 
	}
	
	function verifylogin($mail,$pass){
		if(($this->mail == "$mail") && ($this->password == "$pass")) {
		    if($this->active=='1'){
		  		return '1';//active!
		    }
		  	else if($this->active=='0'){
		  		return "2";//account not active
		  	}else return '3';//shouldnt take this value
		}elseif ($this->mail == "$mail" && $this->password != "$pass")
				return '4'; //inbvalid password
				else return '5';//invalid email
	}
	
	function stop(){
		$this->cone->stop();
	}
	
	function sendmailprevinfo($id){
	$res1 = $this->cone->query("SELECT guard_password_tx,guard_mail_tx FROM users WHERE guard_id_n=$id;"); 		
	$obj = mysql_fetch_row($res1);
	echo $pass = $obj[0];
	echo $mail = $obj[1];
/*
	$email_content = "$sit_domaine_tx/update_lifegurad.php?id=10&s_id=97097097209098709709kihHLK";  // s_id = session_id           
	$email_title       = "Confirmation/$sit_domaine_tx";
	
	$message         ="<html><head><title>Titre</title></head><body> $email_content</body></html>";
	
	$headers           = "From: $com_business_email_tx \n";
	$headers          .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
	$headers          .= 'Content-Transfer-Encoding: 8bit';
	
	
	// Send an email to the client..
	@mail("$txtemail","$email_title",$message ,$headers);
  */  }

 function show_per_form(){
 	switch ($this->sex) {
	case 0:
		$selected0 = "selected";
		$selected1 = "";
		$selected2 = "";
		break;
	case 1:
		$selected0 = "";
		$selected1 = "selected";
		$selected2 = "";
		break;
	case 2:
		$selected0 = "";
		$selected1 = "";
		$selected2 = "selected";
		
		break;

	default:
		break;
	}
?>
<link href="../css/screen.css" media="screen" type="text/css" rel="stylesheet">

<form class="cmxform" id="signupForm" method="POST" style="width:740px;" action="index.php">
 	
   <fieldset id="left_form">
		<legend>Informations</legend>
		<table><tr><td>
		<p>
			<label for="lname">Nom </label>
			<input id="lname" name="lname" value="<?=$this->lname?>"/> 
		</p>
		<p>
			<label for="fname">Pr&eacute;nom</label>
			<input id="fname" name="fname" value="<?=$this->name?>"/>
		</p>
		<p>
			<label for="photo">Photo</label>
				<input id="fileToUpload" type="file" name="fileToUpload">
				<input type="button" value="upload" onclick="ajaxFileUpload(<?=$this->id_user?>);">
		</p>
		<p>
			<label for="gendre">Gendre</label>
			<select name="gendre" id="gendre">
			  <option value="0" <?=$selected0?> > -----  </option> 
			  <option value="1" <?=$selected1?> > Male   </option> 
			  <option value="2" <?=$selected2?> > Female </option> 
			</select>
		</p>
		<p>
			<label for="tel">Tel</label>
			<input id="tel" name="tel" value="<?=$this->tel?>" />
		</p>
		<p>
			<input class="submit" type="button" value="Submit" name="sbt" onclick=" update_per_info('<?=$this->id_user?>')" />
		</p>
		</td>
		<td>
		<img id="per_photo" src="../members/upload/<?=$this->photo?>" width="200px">
		</td>
		</tr>
		</table>
	</fieldset>
</form>		

<div id='result' class="result"> </div>
<?
 }
//------------------------END OF FUNCTION SHOW PERSO FORM
}
?>